function t(t) {
    return t && t.__esModule ? t : {
        default: t
    }
}

function e() {
    var t = {
        region: "" + i.
        default.qiniu,
        uptokenURL: i.
        default.basePath + "/qiniu.html?siteid=" + i.
        default.siteid,
        domain: "" + i.
        default.qnimgUrl,
        shouldUseQiniuFileName: !1
    };
    qiniuUp.default.init(t)
}
// const app = getApp()
import http from '../../util/request.js';
var qiniuUp = t(require("../../../utils/qiniuUploader")),
    i = t(require("../../../etc/config")),
    app = getApp(),
    s = require("../../../utils/WxNotificationCenter.js");
Page({
    data: {
        files: [],
        maxImageNum: 15
    },
    onLoad: function () {
        http.get('user', {
            uid: wx.getStorageSync("user").id
        }).then(data => {
            this.setData({
                user: data,
                files: data.photolist ? data.photolist : []
            });
            // console.log(this.data.files)
        });
        this.$wuxToast = app.Wux().$wuxToast.$wuxToast
    },
    onShow: function () {},
    // getData: function() {
    //     var t = this;

    // },
    getPayment: function () {
        app.WxService.navigateTo("/pages/buy/payment")
    },
    chooseImage: function (t) {
        var e = this;
        var t = this;
        if ((this.data.user.vip == 0 || this.data.user.vip1 == 1) && (e.data.files.length < e.data.maxImageNum)) {
            /*
            wx.showToast({
              title: "最多只能上传" + e.data.maxImageNum + "张图，开通会员无限制上传",
              duration:2500,
              icon:"none"
            })
            return false;
           */
        }
        wx.showToast({
            title: '正在上传...',
            icon: 'loading',
            mask: true,
            duration: 10000
        });
        wx.chooseImage({
            count: 1,
            sizeType: ['compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
                var tempFilePaths = res.tempFilePaths;
                let siteroot = app.siteInfo.siteroot;
                // siteroot = siteroot.replace('app/index.php', 'web/index.php');
                let upurl = siteroot + '?i=' + app.siteInfo.uniacid + '&c=utility&a=file&do=upload&thumb=0';
                wx.uploadFile({
                    url: upurl,
                    filePath: tempFilePaths[0],
                    name: 'file',
                    formData: {},
                    header: {},
                    success: function (res) {
                        // console.log(JSON.parse(res.data).url);return false;
                        var url = JSON.parse(res.data).url;
                        var files = Array.from(t.data.files)
                        console.log('png',url);
                        console.log(t.data.files);
                        console.log(files);
                        t.setData({
                            files: files.concat(url)
                        })
                        http.get('setimgs', {
                            imgs: t.data.files.join(','),
                            uid: wx.getStorageSync("user").id
                        }).then(data => {

                        });
                        wx.hideToast();
                    },
                })
            },
        })

    },
    uploadDIY: function (t) {
        var i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null;
        e(), qiniuUp.
        default.upload(t, function (t) {
            i(t.imageURL)
        })
    },
    deleteImage: function (e) {
        var that = this
        var files = Object.values(this.data.files)
        console.log(this.data.files)
        console.log(e.currentTarget.id)
        // var id = e.currentTarget.id
        // app.WxService.showModal({
        //     title: "提示",
        //     content: "确定要删除该图片？"

        // }).then(function (e) {
        //     console.log(e.confirm)
        //     1 == e.confirm && (
        //         upLoadimgs = this.data.files.filter(
        //             function (e, i) {
        //                 return !(i == id)
        //             },
        //             console.log(upLoadimgs)
        //         ),
        //         console.log('!!!!!!!!!!!!!!!', upLoadimgs),
        //         this.setData({
        //             files: upLoadimgs
        //         }),
        //         http.get('setimgs', {
        //             imgs: this.data.files.join(','),
        //             uid: wx.getStorageSync("user").id
        //         }).then(data => {}))
        // });

        var id = e.currentTarget.id
        wx.showModal({
            title: '提示',
            content: '确定要删除该图片？',
            success(e) {
                if (e.confirm) {
                    //     upLoadimgs = this.data.files.filter(
                    //     function (e, i) {
                    //     return !(i == id)
                    //     },
                    //     console.log(upLoadimgs)
                    // ), 
                    // console.log('!!!!!!!!!!!!!!!',upLoadimgs),
                    // this.setData({
                    //     files: upLoadimgs
                    // }), 
                    // http.get('setimgs', {
                    //     imgs: this.data.files.join(','),
                    //     uid: wx.getStorageSync("user").id
                    // }).then(data => {})
                    console.log(id)
                    console.log('!!!!!!!!!!!!',files)
                    var upDateImgs = files.filter(
                        function (e, i) {
                            return !(i == id)
                        },
                    )
                    console.log('updata',upDateImgs)
                    that.setData({
                            files: upDateImgs
                        }),
                        http.get('setimgs', {
                            imgs: that.data.files.join(','),
                            uid: wx.getStorageSync("user").id
                        }).then(data => {})
                } else if (e.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
    showToastSuc: function (t, e) {
        this.$wuxToast.show({
            type: "success",
            timer: 1500,
            color: "#fff",
            text: "" + t,
            success: function () {
                return e
            }
        })
    },
    showToastErr: function (t, e) {
        this.$wuxToast.show({
            type: "forbidden",
            timer: 1500,
            color: "#fff",
            text: "" + t,
            success: function () {
                return e
            }
        })
    },
    onUnload: function () {
        s.postNotificationName("UserNotification")
    }
});